package com.ruoyi.web.controller.api.coupon;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.system.domain.PAskCoupon;
import com.ruoyi.system.domain.PAskCouponLog;
import com.ruoyi.system.service.IPAskCouponLogService;
import com.ruoyi.system.service.IPAskCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: wk
 * @Date: 2022/7/29 10:25
 * @Version: 1.0
 */
@Api(tags = {"前端-优惠券管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/coupon")
public class CouponApiController {
    private final IPAskCouponService iPAskCouponService;
    private final IPAskCouponLogService iPAskCouponLogService;

    @ApiOperation("根据咨询订单获取优惠券列表")
    @GetMapping("/get-list")
    public TableDataInfo<PAskCoupon> list(PAskCoupon bo, PageQuery pageQuery) {
        return iPAskCouponService.queryPageMyList(bo, pageQuery);
    }

    @ApiOperation("查询领取优惠券记录列表")
    @GetMapping("/get-list-user")
    public TableDataInfo<PAskCouponLog> list(@RequestParam(value = "userType", required = false) String userType, PageQuery pageQuery) {
        return iPAskCouponLogService.queryPageMyList(userType, pageQuery);
    }

    @ApiOperation("新增领取优惠券记录")
    @RepeatSubmit()
    @PostMapping("/add-log")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PAskCouponLog bo) {
        iPAskCouponLogService.insertByFont(bo);
        return R.ok("新增成功！");
    }

}
